<?PHP
/**
 * User: Paulo Fournier
 * Date: 05-08-2013
 * Type: application/json
 * Used to retrieve the list of POI in a JSON document
 */

require_once '../../../../php/settings/config.php';
require_once '../../../../php/lib/user.php';

session_start();

$success = FALSE;   //used to check if the process was finished successfully
$errorCode = NULL;  //in case of error, will contain the code error that will be return to the client

$user = unserialize($_SESSION["user"]);

//init connection
$ch = curl_init(CRUD_URL . "/poisForUserId/" . $user->userId);
//set connection paramaters
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "charset: UTF-8"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_POST, FALSE);
//get response
$rst = curl_exec($ch);

//request failure
if ($rst === false) {
    $err = curl_error($ch);
    $errorCode = 2;

    error_log("request: NOK");
    error_log('Curl error: ' . $err);
} //request success
else {

    $response = json_decode($rst, TRUE);

    //auth successfully
    if ($response['success']) {

        $success = TRUE;

        echo json_encode($response["retVal"]);

    }
    //auth un-successfully
    else {
        $errorCode = 3;
    }

}